<template>
  <div class="order-box">
    <ref-table :search='search' ref='crud' :option='option' :data.sync='data'>
      <!-- <template #action>
        <div class='mb20'>
          <el-button type='primary' size='small' icon='el-icon-plus' @click='openDialog("add")'>新增</el-button>
          <el-button type='primary' size='small' icon='el-icon-download'>导出</el-button>
          <el-button type='primary' size='small' icon='el-icon-upload2'>导入</el-button>
          <el-button type='primary' size='small' icon='el-icon-refresh'>刷新缓存</el-button>
          <el-button type='primary' size='small' icon='el-icon-s-release'>回收站</el-button>
        </div>
      </template> -->
      <template #menu='{row}'>
        <el-button type="text" icon="el-icon-setting" size="mini" @click='editRow(row)'>字典配置</el-button>
      </template>
    </ref-table>
    <dict-drawer
      :detail = 'detail'
      :visible='drawerVisible'
      @close='showDrawer' />
  </div>
</template>

<script>
  import refTable from '@/plugins/table/';
  import tableMix from '@/mixins/table';
  import dictDrawer from './dict/drawer';
  export default {
    data () {
      return {
        loading: false,
        search: {},
        data: [],
        drawerVisible: false
      }
    },
    mixins: [tableMix],
    components: {
      refTable,
      dictDrawer
    },
    created () {
      this.detail = {};
      this.option = {
        queryUrl: '/dataDictionary/queryDataDictionary',
        menu: true,
        column: [
          {
            label: '字典名称',
            prop: 'name',
            search: true,
            rules: [
              {
                required: true,
                message: '请输入字典名称',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '字典编号',
            prop: 'bh',
            search: true,
            rules: [
              {
                required: true,
                message: '请输入字典编号',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '描述',
            prop: 'dec'
          }
        ]
      }
    },
    mounted () {
      this.$refs.crud.onLoad()
    },
    methods: {
      editRow (row) {
        this.detail = row;
        this.showDrawer();
      },
      showDrawer () {
        this.drawerVisible = !this.drawerVisible;
      },
      addRow (row,done) {
        const params = {
          dic_bh:row.bh,
          key_name:row.name,
          dic_dec: row.dec
        };
        this.axios({
          url: '/dataDictionary/insertDataDicList',
          method: 'post',
          data: params
        }).then(() => {
          this.$message.success('添加成功');
        })
      }
    }
  }
  
</script>
